package im.elephas.androfan.common.widget;

import im.elephas.androfan.R;
import im.elephas.androfan.activity.AndroFanActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;

public class PageWidget extends GeneralWidget implements OnClickListener {
	
	public interface PageOpration {
		public void doPage(int page);
	}

	public PageOpration mPageOpration;
	
	private View changePageView;
	private Button prevButton;
	private Button nextButton;
	private int page;
	
	public PageWidget(ViewGroup parentView,
			AndroFanActivity androFanActivity, PageOpration pageOpration, int currentPage) {
		super(parentView, androFanActivity);
		this.mPageOpration = pageOpration;
		this.page = currentPage;

		changePageView = getActivity().getLayoutInflater().inflate(
				R.layout.statusespages, null);
		super.setWidgetView(changePageView);
		
		prevButton = (Button) changePageView.findViewById(R.id.prevButton);
		nextButton = (Button) changePageView.findViewById(R.id.nextButton);
		
		prevButton.setOnClickListener(this);
		nextButton.setOnClickListener(this);
		
		if (this.page <= 1) 
			prevButton.setEnabled(false);
	}

	@Override
	public void onClick(View v) {
		if (v.equals(prevButton)) {
			page--;
		}
		if (v.equals(nextButton)) {
			page++;
		}
		mPageOpration.doPage(page);
		
		prevButton.setEnabled(false);
		nextButton.setEnabled(false);
	}
}
